var express = require('express');
var router = express.Router();
var http = require("http");
var countries = require("../bin/country.js");
var startCity = require("../bin/startCity.js");

// 轮播图
router.get("/api/loop",(req,res)=>{
  var list = [
    {img:"http://192.168.15.224:3000/images/loop/1.jpg"},
    {img:"http://192.168.15.224:3000/images/loop/2.jpg"},
    {img:"http://192.168.15.224:3000/images/loop/3.jpg"},
    {img:"http://192.168.15.224:3000/images/loop/4.jpg"},
    {img:"http://192.168.15.224:3000/images/loop/5.jpg"},
    {img:"http://192.168.15.224:3000/images/loop/6.jpg"},
  ]
  res.json({err:0,msg:list})
})
// 请求九宫格接口
router.get("/api/items",(req,res)=>{
  var items = [
    {title:"机票",img:"images/items/1.png"},
    {title:"旅游",img:"images/items/2.png"},
    {title:"签证",img:"images/items/3.png"},
    {title:"欧洲环游",img:"images/items/4.png"},
    {title:"门票",img:"images/items/5.png"},
    {title:"当地玩乐",img:"images/items/6.png"},
    {title:"私家团",img:"images/items/7.png"},
    {title:"更多",img:"images/items/8.png"}
  ]
  res.json({err:0,msg:items})
})

// 搜索国家接口接口
router.get("/api/search",(req,res)=>{
    countries.find()
    .then(data=>{
        // console.log(data);
        res.json({err:0,msg:data})
    })
})
// 出发城市
router.get("/api/searchStart",(req,res)=>{
    startCity.find()
    .then(data=>{
        console.log(data)
        res.json({err:0,msg:data})
    })
})

// 首页请求旅游信息
router.get("/api/tripInfo",(req,res)=>{
    // console.log(req.query.page)
   http.get("http://m.kaytrip.com/welcome/ajax-index?page="+req.query.page,function(res2){
        var data = "";
        res2.on("data",function(d){
            data+=d;
        });
        res2.on("end",function(){
            var o = JSON.parse(data);
            // console.log(o)
            res.json(o);
        });
    });
});
// 首页开元精品请求
router.get("/api/goodTrip",(req,res)=>{
//   console.log(req.query)
  // console.log(333)
  http.get("http://m.kaytrip.com/product/ajax_linelist_Bytype?page="+req.query.page+"&page_size=5&type=hot",function(res2){
        var data = "";
        res2.on("data",function(d){
            data+=d;
        });
        res2.on("end",function(){
            var o = JSON.parse(data);
            // console.log(o)
            res.json(o);
        });
    });
});

// 新品路线请求
router.get("/api/newLine",(req,res)=>{
    // console.log(req.query)
    http.get("http://m.kaytrip.com/product/ajax_linelist_Bytype?page="+req.query.page+"&page_size=5&type=new_pro",function(res2){
        var data = "";
        res2.on("data",function(d){
            data+=d;
        });
        res2.on("end",function(){
            var o = JSON.parse(data);
            // console.log(o)
            res.json(o);
        });
    });
});

// 优品特色接口
router.get("/api/specialTrip",(req,res)=>{
    http.get("http://m.kaytrip.com/product/ajax_linelist_Bytype?page="+req.query.page+"&page_size=5&type=good",function(res2){
        var data = "";
        res2.on("data",function(d){
            data+=d;
        });
        res2.on("end",function(){
            var o = JSON.parse(data);
            // console.log(o)
            res.json(o);
        });
    });
})






module.exports = router;

 


